package co.fitstart.entity.order;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.core.format.DecimalFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name = "order_price_attr")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class OrderPriceAttribute {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 价格 */
    @DecimalFormat
    private int offer;
    
    /** 类型 */
    @Enumerated(EnumType.ORDINAL)
    private OrderPriceType type;
    
    /** 发生时间 */
    private Date occurTime;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Order order;
    
    /**
     * 
     */
    public OrderPriceAttribute() {
        
    }
    
    /**
     * 
     * @param type
     * @param order
     */
    public OrderPriceAttribute(OrderPriceType type, Order order) {
        this.type = type;
        this.order = order;
        this.occurTime = new Date();
        if(this.type.isSale()) {
            this.offer = order.getPrice();
        } else if (this.type.isRefund()) {
            this.offer = order.getRefundPrice();
        }
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the offer
     */
    public int getOffer() {
        return offer;
    }

    /**
     * @return the type
     */
    public OrderPriceType getType() {
        return type;
    }

    /**
     * @return the occurTime
     */
    public Date getOccurTime() {
        return occurTime;
    }

    /**
     * @return the order
     */
    public Order getOrder() {
        return order;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param offer the offer to set
     */
    public void setOffer(int offer) {
        this.offer = offer;
    }

    /**
     * @param type the type to set
     */
    public void setType(OrderPriceType type) {
        this.type = type;
    }

    /**
     * @param occurTime the occurTime to set
     */
    public void setOccurTime(Date occurTime) {
        this.occurTime = occurTime;
    }

    /**
     * @param order the order to set
     */
    public void setOrder(Order order) {
        this.order = order;
    }

}
